Jump to content

Library Integration for DIS - Preparing the Runtime Settings

From RidgeRun Developer Wiki

Follow us on: YouTube Twitter LinkedIn Email Share this page

Share This Page

Preferred Partner Logo 3 Partner Program Banner



Runtime Settings Preparation

Before creating the DigitalStabilizer, the application must configure both the stabilization parameters and the runtime settings required by the selected backend.

The stabilization parameters define the behavior of the pipeline, such as optical flow configuration, smoothing settings, and the algorithms used for motion estimation and image transformation.

Common Stabilization Parameters

The example first creates and configures the optical flow parameters:

auto optical_flow_params =
    std::make_shared<rvs::OpticalFlowParams>();

optical_flow_params->feature_redetect_interval =
    opts.harris_refresh;

optical_flow_params->feature_max_corners =
    opts.max_corners;

optical_flow_params->opt_flow_num_levels =
    opts.pyramid_levels;

These parameters are then attached to the DigitalStabilizer configuration:

auto digital_params =
    std::make_shared<
        rvs::DigitalStabilizerParams>();

digital_params->smoothing_frames =
    opts.smoothing_frames;

digital_params->crop_margin =
    opts.crop_margin;

digital_params->optical_flow_params =
    optical_flow_params;

digital_params->smoothing_algorithm =
    rvs::SmoothingAlgorithms::kGaussian;

The resulting configuration hierarchy is:

DigitalStabilizerParams
    ├── OpticalFlowParams
    ├── Smoothing Configuration
    └── Transform Configuration

HostAllocator (OpenCV Backend)

For the OpenCV backend, no special runtime configuration is required. The example selects the OpenCV implementations for both optical flow and geometric transformations:

digital_params->optical_flow_algorithm =
    rvs::OpticalFlowAlgorithms::
        kPyrLKOpenCV;

digital_params->transform_algorithm =
    rvs::TransformAlgorithms::
        kTransformOpenCV;

No runtime settings object is created:

std::shared_ptr<
    rvs::IRuntimeSettings>
        runtime_settings = nullptr;

The stabilizer is then created directly:

rvs::DigitalStabilizer stabilizer(
    digital_params,
    runtime_settings);

CudaAllocator (CUDA Backend)

For the CUDA backend, the example selects the CUDA implementations:

digital_params->optical_flow_algorithm =
    rvs::OpticalFlowAlgorithms::
        kPyrLKCUDA;

digital_params->transform_algorithm =
    rvs::TransformAlgorithms::
        kTransformCUDA;

Unlike the OpenCV backend, CUDA requires additional runtime configuration. The example creates a CUDA stream and stores it in a CUDA-specific runtime settings object:

auto cuda_runtime_settings =
    std::make_shared<
        rvs::CudaRuntimeSettings>();

cudaStreamCreateWithFlags(
    &cuda_stream,
    cudaStreamNonBlocking);

cuda_runtime_settings->cuda_stream =
    cuda_stream;

cuda_runtime_settings->async = true;

The CUDA runtime settings are then exposed through the common runtime settings interface:

std::shared_ptr<
    rvs::IRuntimeSettings>
        runtime_settings =
            cuda_runtime_settings;

The resulting configuration hierarchy is:

IRuntimeSettings
        ↑
CudaRuntimeSettings
    ├── CUDA Stream
    └── Async Execution Mode

Finally, the stabilizer is created using the configured parameters and runtime settings:

rvs::DigitalStabilizer stabilizer(
    digital_params,
    runtime_settings);




Cookies help us deliver our services. By using our services, you agree to our use of cookies.